package kotan.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import kotan.Kotan;

/**
 * Application menu.
 * 
 * @author shuji.w6e
 * @since 1.0
 */
public class AppMenu {

    private JMenuBar menuBar;

    /**
     * Constructor.
     */
    public AppMenu() {
        initComponents();
    }

    private void initComponents() {
        menuBar = new JMenuBar();
        // File
        JMenu fileMenu = new JMenu("File");
        menuBar.add(fileMenu);
        {
            JMenuItem quitMenu = new JMenuItem("Quit Kotan");
            quitMenu.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    onQuit();
                }
            });
            fileMenu.add(quitMenu);
        }
        // Server
        JMenu serverMenu = new JMenu("Server");
        menuBar.add(serverMenu);
        {
            JMenuItem showAdminMenu = new JMenuItem("Show admin");
            showAdminMenu.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    onShowAdmin();
                }
            });
            serverMenu.add(showAdminMenu);
        }
        // Help
        JMenu helpMenu = new JMenu("Help");
        menuBar.add(helpMenu);
    }

    protected void onQuit() {
        Kotan.get().shutdown();
        Kotan.get().getMainFrame().dispose();
    }

    protected void onShowAdmin() {
        Kotan.get().showAdminOnBrowser();
    }

    protected JMenuBar getMenuBar() {
        return menuBar;
    }
}
